package com.hu.bookstore.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.bookstore.Mapper.bookMapper;
import com.hu.bookstore.Mapper.cateGory;
import com.hu.bookstorecommon.entity.DataPage;
import com.hu.bookstorecommon.entity.book;
import com.hu.bookstorecommon.entity.category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class bookServiceImpl implements bookService {

  @Autowired
  private bookMapper bookMapper;

  @Autowired
  private cateGory cateGory;



    @Override
    public DataPage<book> getAllBooks(Integer pageNum,  Integer pageSize,Integer cid, String authorName, String bookName) {

        PageHelper.startPage(pageNum, pageSize);

        List<book> books = bookMapper.selectAllBooks(authorName, bookName, cid);

        PageInfo<book> pageInfo=new PageInfo<>(books);
         DataPage<book> dataPage=new DataPage<>();
         dataPage.setPageSize(pageSize);
         dataPage.setRowCount((int)pageInfo.getTotal());
         dataPage.setPageCount(pageInfo.getPages());
         dataPage.setDataList(books);
         dataPage.setPageNum(pageNum);


        return dataPage;
    }

    @Override
    public List<category> getAllCateGory() {
        return cateGory.selectCate();
    }
}
